package com.pattern.structure.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yangguanzan
 * @date 7/3/22
 * @description
 */
public class Branch implements IBranch {

    private List<ICorp> children;

    public Branch() {
        children = new ArrayList<>();
    }

    @Override
    public void add(ICorp node) {
        children.add(node);
    }

    @Override
    public void remove(ICorp node) {
        children.remove(node);
    }

    @Override
    public ICorp getChild(int i) {
        return children.get(i);
    }

    @Override
    public void operation() {
        System.out.println("Branch operation");
        for (ICorp corp:children) {
            corp.operation();
        }
    }
}
